package cn.micro.http;

import okhttp3.logging.HttpLoggingInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;

/**
 * OkHttp logger, Slf4j and console log.
 */
public enum HttpLogger implements HttpLoggingInterceptor.Logger {

    /**
     * http 日志：Slf4j
     */
    Slf4j() {
        @Override
        public void log(@Nonnull String message) {
            log.info(message);
        }
    },

    /**
     * http 日志：Console
     */
    Console() {
        @Override
        public void log(@Nonnull String message) {
            // 统一添加前缀，方便在茫茫日志中查看
            System.out.print("ConsoleLogger: ");
            System.out.println(message);
        }
    };

    private static final Logger log = LoggerFactory.getLogger(HttpLogger.class);

}
